package com.example.pt.repository;

import com.example.pt.entity.Post;
import com.example.pt.entity.Reply;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ReplyRepository extends JpaRepository<Reply, Long> {

    @Query("SELECT r FROM Reply r WHERE r.post_id = :post_id")
    List<Reply> findByPostId(@Param("post_id") Long post_id);

    @Modifying
    @Transactional
    @Query("DELETE FROM Reply r WHERE r.reply_id = :reply_id AND r.user_id = :user_id")
    int deleteByReplyIdAndUserId(@Param("reply_id") Long reply_id, @Param("user_id") Long user_id);
}
